package test.jdkproxy;

import java.lang.reflect.Proxy;

public class JDKProxyFactory {

    public UserService getProxyObject(UserService userService){
        return (UserService) Proxy.newProxyInstance(userService.getClass().getClassLoader(),
                userService.getClass().getInterfaces(),
                new UserServiceInvohander(userService));
    }

    public static void main(String[] args) {
        JDKProxyFactory foctory=new JDKProxyFactory();
        //目标对象
        UserServiceImpl target=new UserServiceImpl();
        //返回的是代理对象
        UserService userService=foctory.getProxyObject(target);

        userService.insert();
        System.out.println("-------------------------");
        userService.delete();
    }
}
